<?php
namespace Apps\BoxEdu\Model;

use Think\Model;

class EduAttachModel extends \BaseModel
{
    public function load($attid = "")
    {
        $data = $this->find($attid);
        if (!$data) {
            return false;
        }
        $video_url = $data['video_url'];
        $data['video_info'] = S(md5($video_url));
        if ($video_url && (!$data['video_info'])) {
            $videoClass = new \Common\Org\Video\Video();
            $vodlist = $videoClass->VodList(array('url' => $video_url));
            $data['video_info'] = $vodlist['0'];
            S(md5($video_url), $data['video_info']);
        }
        return $data;
    }


    /*********下载列表********/
    public function get($where = 1, $limit = "", $orderBy = "attid desc")
    {

        /********有limit需要分页***/
        if ($limit) {
            $count = $this->where($where)->count();
            $page = setPager($count, $limit);
            $limit = $page['firstRow'] . "," . $page['listRows'];
        }
        $data = $this->where($where)->field("attid")->limit($limit)->order($orderBy)->select();
        if ($data) {
            foreach ($data as $one) {
                $re[] = $this->load($one['attid']);
            }
        }
        if ($limit) {
            return $data ? array('count' => $count, 'list' => $re, 'pager' => $page) : $data;

        } else {
            return $re;
        }

    }
}
 